﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <script src="~/js/frame.js"></script>
</head>
<body>
    <div class="container-fluid">
        <form id="form">
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle required">字段中文名</div>
                    <div class="formcontent">
                        <input name="ColumnName" type="text" class="form-control required" placeholder="">
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle required">字段名称</div>
                    <div class="formcontent">
                        <input name="PhysicalColumnName" type="text" class="form-control required" placeholder="" readonly>
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle required">字段类别</div>
                    <div class="formcontent">
                        <select class="form-control required" id="ColumnType" name="ColumnType" onchange="ColumnTypeChange()" readonly>
                            <option value="10" selected="selected">字符串（nvarchar）</option>
                            <option value="20">整数（int）</option>
                            <option value="30">小数（numeric）</option>
                            <option value="40">日期（datetime）</option>
                            <option value="50">大文本（longtext）</option>
                        </select>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="formtitle required">字段长度</div>
                    <div class="formcontent">
                        <input type="number" id="ColumnLenght" name="ColumnLenght" type="text" class="form-control required" placeholder="" value="100" readonly>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="formtitle ">精度</div>
                    <div class="formcontent">
                        <input type="number" id="ColumnDecimalPoint" name="ColumnDecimalPoint" type="text" class="form-control " placeholder="" readonly>
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-6">
                    <div class="formtitle required">控件类型</div>
                    <div class="formcontent">
                        <select class="form-control required" name="BindControl" id="BindControl">
                            <option value="10" selected="selected">文本输入框</option>
                            <option value="20">数字框</option>
                            <option value="30">日期选择</option>
                            <option value="40">下拉选择</option>
                            <option value="50">单选组</option>
                            <option value="60">多选组</option>
                            <option value="70">富文本编辑器</option>
                        </select>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="formtitle">绑定代码项</div>
                    <div class="formcontent">
                        <select class="chosen-select form-control required" name="BindCode" id="BindCode">
                        </select>
                    </div>
                </div>
            </div>
            <div class="formrow">
                <div class="col-xs-12">
                    <div class="formtitle">排序</div>
                    <div class="formcontent">
                        <input name="SortNum" type="text" class="form-control" placeholder="" value="0">
                    </div>
                </div>
            </div>
            <div style="display:none">
                <input name="ColumnGuid" type="text" class="form-control" placeholder="">
            </div>
            <div class="formbtnop">
                <button class="btn btn-primary cloudbtn" type="button" onclick="Save()"><span class="btntext">保 存</span></button>
                <button class="btn cloudbtn" type="button" onclick="Close()"><span class="btntext">关 闭</span></button>
            </div>
        </form>
    </div>
    <script>
        var validator = $("#form").validate();
        BindCodeList();
        $(function () {
            LoadDetail();
        })
        function LoadDetail() {
            var param = { "ColumnGuid": GetUrlParam("columnguid") }
            CloudPost(param, "opdetail", function (res) {
                if (res.code == 0) {
                    $("#form").SetForm(res.data);
                }
            })
        }
        function Save() {
            if (validator.form()) {
                var param = $("#form").GetForm();
                CloudPost(param, "opupdate", function (res) {
                    if (res.code == 0) {
                        OpenSuccess("保存成功！", function () {
                            CloseDialog();
                        })
                    } else {
                        OpenFail(res.data)
                    }
                })
            }
        }
        function Close() {
            CloseDialog();
        }
        function ColumnTypeChange(e) {
            var selecyvalue = $("#ColumnType").val();
            switch (selecyvalue) {
                case "10":
                    $("#ColumnLenght").val("100");
                    $("#BindControl").val("10")
                    break;
                case "20":
                    $("#ColumnLenght").val("11")
                    $("#BindControl").val("20")
                    break;
                case "30":
                    $("#ColumnLenght").val("11")
                    $("#BindControl").val("20")
                    $("#ColumnDecimalPoint").val("2")
                    break;
                case "40":
                    $("#ColumnLenght").val("0")
                    $("#BindControl").val("30")
                    break;
                case "50":
                    $("#ColumnLenght").val("0")
                    $("#BindControl").val("70")
                    break;
            }
        }
        function BindCodeList() {
            CloudPostSync({}, GetRootPath() + "frame/dmp/codemain/oplistall", function (res) {
                if (res.code == 0) {
                    $("#BindCode")[0].options.add(new Option("请选择", ""));
                    $(res.data).each(function () {
                        $("#BindCode")[0].options.add(new Option(this.CodeName, this.CodeGuid));
                    })
                }
            })
        }
    </script>
</body>
</html>
